package com.taoyibao.hongcanting.ui.home.delegate;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.constant.NetCode;
import com.taoyibao.hongcanting.model.CartSimpleInfoModel;
import com.taoyibao.hongcanting.model.CompanyBaseModel;
import com.taoyibao.hongcanting.model.ShoppingCartModel;
import com.taoyibao.hongcanting.ui.home.views.CartListArea;
import com.taoyibao.hongcanting.utils.CodeUtils;

import java.util.List;

/**
 * @author TangAnna
 * @description:
 * @date :${DATA} 17:10
 */
public class ShoppingCartDelegate extends BackToolbarDelegate {
    private CartListArea mCartListArea;
    public TextView mRightText;
//    public int mTotalCount = 0;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_shopping_cart;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("购物车");
        //右上角清空
        setRightText(CodeUtils.getIdString(R.string.string_clearAll));
        setLoadingView();
        mCartListArea = get(R.id.scla_shoppingCart_list);
        mCartListArea.isShowCountController(true);
    }

    /**
     * 购物车set数据
     *
     * @param shoppingCartModel
     */
    public void setData(List<ShoppingCartModel> shoppingCartModel) {
        if (shoppingCartModel == null || shoppingCartModel.size() < 1) {//没数据
            setEmptyView(true);
            return;
        }
        mCartListArea.setData(shoppingCartModel);
        setEmptyView(false);
    }

    /**
     * 设置购物车底部数据
     */
    public void setBottomData(CompanyBaseModel<List<CartSimpleInfoModel>> listCompanyBaseModel) {
        if (listCompanyBaseModel.code == NetCode.HTTP_200 && listCompanyBaseModel.data != null && listCompanyBaseModel.data.size() > 0) {
            CartSimpleInfoModel data = listCompanyBaseModel.data.get(0);
            ((TextView) get(R.id.tv_totalMoney)).setText("总价:" + CodeUtils.formatAmountUnit(data.discount_price));
            ((TextView) get(R.id.tv_couponMoney)).setText("已优惠:" + CodeUtils.formatAmountUnit(data.origin_price - data.discount_price));
        } else {
            ((TextView) get(R.id.tv_totalMoney)).setText("总价:￥0.00");
            ((TextView) get(R.id.tv_couponMoney)).setText("已优惠:￥0.00");
        }
    }

    /**
     * 设置空数据页面  true  空页面  false 数据页面
     */
    public void setEmptyView(boolean isEmptyView) {
        get(R.id.emptyView).setVisibility(isEmptyView ? View.VISIBLE : View.GONE);
        get(R.id.layout_dataView).setVisibility(isEmptyView ? View.GONE : View.VISIBLE);
        //去下单按钮不可点击
        Button btnNext = get(R.id.tv_includShoppingCart_next);
        btnNext.setClickable(!isEmptyView);
        btnNext.setEnabled(!isEmptyView);
        setHideRightAll(isEmptyView);
        Button btnDianCan = get(R.id.tv_includShoppingCart_continueAdd);
        if (isEmptyView) {
            btnDianCan.setText(CodeUtils.getIdString(R.string.cart_starDianCan));
            ((TextView) get(R.id.tv_totalMoney)).setText("总价:￥0");
            ((TextView) get(R.id.tv_couponMoney)).setText("已优惠:￥0");
        } else {
            btnDianCan.setText(CodeUtils.getIdString(R.string.string_continue));

        }
    }
}
